package com.smart.nine.spel.summary;

import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

/**
 * 测试类
 *
 * @author junrui.wang
 * @create 2019/3/18
 */
public class SpelHello {
    public static void main(String[] args) {
        //针对实例对象的属性进行求值
        User user = new User();
        user.setName("Tom");
        user.setCredits(100);
        ExpressionParser expressionParser = new SpelExpressionParser();
        EvaluationContext evaluationContext = new StandardEvaluationContext(user);
        String userName = expressionParser.parseExpression("name").getValue(evaluationContext, String.class);
        System.out.println(userName);
    }
}
